 #!/usr/bin/perl
use warnings;
use strict;
use Cwd;
 
use Time::SoFar qw( runtime runinterval figuretimes ); 
use Statistics::R;

my $debugmode=0;


my ( $workingdir,  $charttype ) = @ARGV;

my $R = Statistics::R->new();

#my $elapsed = runtime();

	if ($debugmode==1)
	{
		$workingdir='C:/carmd-cvs02/Koala';
		chdir($workingdir);
#		$ARGV[0]='boxplotchart';
	}
	#chdir("C:/carmd-cvs01/Data_Parser");
	chdir("$workingdir");
	my $dir=getcwd;
	print "current work directory= $dir, \n\n";

$R->startR;

#$SIG{'INT'} = 'IGNORE';
#my $sincethen = runinterval(1);
#print "=== Starting R: $sincethen seconds\n";

#$elapsed = runtime();

	my $ret = $R->read ;
	#print "$ret \n\n";
	
	
	#$ARGV[0]="boxplotchart";

	#print "arguments \@ARGV[0]: $ARGV[0] \n";
	if ($ARGV[1] =~ /process_capability/i)
	{
		$R->send(	q`source(file="C:/carmd-cvs02/Data_Parser/summary_scripts_R/process_capability.R",
					echo=TRUE)`);
	}
	elsif ($ARGV[1] =~ /pareto_chart/i)
	{
		$R->send(	q`source(file="C:/carmd-cvs02/Data_Parser/summary_scripts_R/pareto_chart.R", 
					echo=TRUE)`);
	}
	elsif ($ARGV[1] =~ /boxplotchart/i)
	{
		$R->send(	q`source(file="C:/carmd-cvs02/Data_Parser/summary_scripts_R/boxplot_chart.R", 
					echo=TRUE)`);
	}
	else
	{
		print "unknow argument passed in";
		END;
	}
	
  	$ret = $R->read;

	$R->stopR() ;
END;
  